package com.lin.springbootexceptionHandling.controller;

import com.lin.springbootexceptionHandling.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * 异常处理器测试, 该类中没有定义自定义异常处理器, 会走全局处理器,
 * 若全局处理器没有配置, 则会走 Spring Boot 默认的处理器
 */
@RestController
public class UserController2 {
    @Autowired
    private UserService userService;

    @GetMapping("/list2/{id}")
    public String getUserList(@PathVariable int id) {
        if (id == 1) throw new IllegalArgumentException("Id is invalid");
        return userService.getUserList().toString();
    }

}
